package com.caldremch.rncodepush;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.microsoft.codepush.react.CodePush;

import java.util.Arrays;
import java.util.List;

import javax.annotation.Nullable;


/**
 *@Description 
 *
 *@Author Caldremch
 *
 *@Date 2017/8/29 15:01
 *
 *@Email huang.zhongxian@zyxr.com
 *
 *
 ┌────────────┬──────────────────────────────────────────────────────────────
────┐
│ Name       │ Deployment Key                                                   │
├────────────┼──────────────────────────────────────────────────────────────
────┤
│ Production │ o81gEtdK25_ZF90J6PHqVtnzTgMx1780f5f1-a921-4b81-b3b5-45c5991139bf │
├────────────┼──────────────────────────────────────────────────────────────
────┤
│ Staging    │ 3BduLWcaMTKR-SAn299P4dob45sN1780f5f1-a921-4b81-b3b5-45c5991139bf │
└────────────┴──────────────────────────────────────────────────────────────
────┘


 *
 **/
public class MyApplication extends Application implements ReactApplication {


    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

        @Override
        public boolean getUseDeveloperSupport() {
            return true;
        }


        //override the getJSBundleFile method in order to let
        //the CodePush runtime determin where to get the JS
        //bundle location from on each app start
        @Nullable
        @Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
        }

        /**
         * Instantiate an instance of the CodePush runtime and add it to
         * the list of existing packages, specifying the right deployment key.
         * if you don't already have it, you can run code-push deloyment ls <appName>
         * -k" to retrieve your key. have it, you can run "code-push deployment ls <appName>"
         * to retrieve you key
         *
         */
        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new CodePush("o81gEtdK25_ZF90J6PHqVtnzTgMx1780f5f1-a921-4b81-b3b5-45c5991139bf", MyApplication.this, true)
            );
        }
    };
    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }
}
